package com.ty.xsl.field;

public class StringFormat extends FieldFormat {

	private static final long serialVersionUID = 6353993575983886200L;
	private int maxLength;
	private int minLength;
	private String regex;

	/**
	 * @return the maxLength
	 */
	public int getMaxLength() {
		return maxLength;
	}

	/**
	 * @param maxLength
	 *            the maxLength to set
	 */
	public void setMaxLength(int maxLength) {
		this.maxLength = maxLength;
	}

	/**
	 * @return the minLength
	 */
	public int getMinLength() {
		return minLength;
	}

	/**
	 * @param minLength
	 *            the minLength to set
	 */
	public void setMinLength(int minLength) {
		this.minLength = minLength;
	}

	/**
	 * @return the regex
	 */
	public String getRegex() {
		return regex;
	}

	/**
	 * @param regex the regex to set
	 */
	public void setRegex(String regex) {
		this.regex = regex;
	}

	@Override
	public String toString(){
		StringBuilder builder = new StringBuilder("{");

		builder.append("\"type\":\"string\"");
		builder.append(", \"maxLength\":").append(maxLength);

		if (minLength > 0){
			builder.append(", \"minLength\":").append(minLength);
		}

		if (regex != null && !"".equals(regex.trim())){
			builder.append(", \"regex\":\"").append(regex).append("\"");
		}

		return builder.append("}").toString();
	}
}
